package com.ddone.service.impl;

import com.ddone.bean.JpaUser;
import com.ddone.bean.User;
import com.ddone.dao.JpaUserDao;
import com.ddone.service.JpaUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ddone
 * @date 2024/3/25-14:37
 */
@Service
public class JpaUserServiceImpl implements JpaUserService {

    @Autowired
    private JpaUserDao jpaUserDao;

    @Override
    public List<JpaUser> findUsers() {
        return jpaUserDao.findAll();
    }

    @Override
    public JpaUser findUserById(Integer id) {
        return jpaUserDao.findById(id).get();
    }

    @Override
    public void saveUser(JpaUser user) {
        jpaUserDao.save(user);
    }

    @Override
    public void updateUser(JpaUser user) {
        jpaUserDao.saveAndFlush(user);
    }

    @Override
    public void deleteUserById(Integer id) {
        jpaUserDao.deleteById(id);
    }
}
